//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    class LineFormatRecord : BiffRecord
    {
        public enum LineWeight
        {
            Hairline = -1,
            Medium = 1,
            Narrow = 0,
            Wide = 2
        }
        public enum LineStyle
        {
            Solid,
            Dash,
            Dot,
            DashDot,
            DashDotDot,
            None,
            DarkGrayPattern,
            MediumGrayPattern,
            LightGrayPattern
        }
        private int rgb;
        private LineStyle lns;
        private LineWeight we;
        private bool _auto;
        private bool _axisOn;
        private bool _autoCo;
        private ushort _icv;
        private ushort Num
        {
            get
            {
                ushort num = 0;
                if (this._auto)  num |= 1 ;
                if (this._axisOn) num |=  4;
                if (this._autoCo) num |= 8;
                return num;
            }
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.LineFormat; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.Write(rgb);
            context.Write((ushort)lns);
            context.Write((ushort)we);
            context.Write(Num);
            context.Write(_icv);
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            this.rgb = context.ReadInt32();
            this.lns = (LineStyle)context.ReadInt16();
            this.we = (LineWeight)context.ReadInt16();
            ushort num = context.ReadUInt16();
            this._auto = (num & 1) == 1;
            this._axisOn = (num & 4) == 4;
            this._autoCo = (num & 8) == 8;
            Contract.Assert(this.Num == num);
            this._icv = context.ReadUInt16();
        }

    }
}